package cn.edu.sjtu.se.peakfactory.dao.impls.hibernate;

import java.util.List;

import org.apache.commons.lang.xwork.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import cn.edu.sjtu.se.lchang.socialnetwork.dao.impls.hibernate.BaseDAOImpl;
import cn.edu.sjtu.se.peakfactory.dao.bean.Game;
import cn.edu.sjtu.se.peakfactory.dao.interfaces.GameDAO;

public class GameDAOImpl extends BaseDAOImpl<Game> implements GameDAO {

	@Override
	public List<Game> findGames(String name, List<Long> tagIds,
			String description) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Game.class);
		if (name != null && StringUtils.isNotBlank(name)) {
			criteria.add(Restrictions.like("name", "%" + name + "%"));
		}
		if (description != null && StringUtils.isNotBlank(description)) {
			criteria.add(Restrictions.like("description", "%" + description
					+ "%"));
		}
		criteria.add(Restrictions.in("tags.id", tagIds));
		return findByCriteria(criteria);
	}
}
